import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import { Message } from 'element-ui';
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import './assets/globa.css'

import 'element-ui/lib/theme-chalk/index.css'
import ElementUI from 'element-ui'
import 'vant/lib/index.css';
import Vant from 'vant';

Vue.use(Vant);
Vue.use(ElementUI)
Vue.use(VueQuillEditor)
//请求拦截
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
//响应拦截
axios.interceptors.response.use(function (response) {
  return response;
}, function (error) {
  if (error) {
    Message.error(error.response.data);
  }
  //获取错误状态码
  var {
    status
  } = error.response;
  if (status == 401) {
    Message.error('登入过期，请重新登入');
    window.sessionStorage.removeItem('token')
    router.push({
      name: 'Login'
    })
  }

  return Promise.reject(error)
})
Vue.prototype.$axios = axios
Vue.prototype.$message = Message
Vue.filter('dateFormat', function (originVal) {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, "0")
  const d = (dt.getDate() + "").padStart(2, "0")
  return `${y}-${m}-${d}`
})
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
